package com.example.viewpager_demo;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * 基础页面适配器　BasePagerAdapter
 *
 */
public class SimplePagerAdapter extends PagerAdapter
{

    private ArrayList<View> viewList = new ArrayList<View>();
    private ArrayList<String> tabTitleList = new ArrayList<String>();

    public ArrayList<View> getViewList()
    {
        return viewList;
    }

    public void addView(View view)
    {
        viewList.add(view);
    }

    public void addView(List<View> views)
    {
        viewList.addAll(views);
    }

    public void addTabtitle(List<String> tabs)
    {
        tabTitleList.addAll(tabs);
    }

    public void setTabtitle(String title)
    {
        tabTitleList.clear();
        tabTitleList.add(title);
    }

    public void setTabtitle(List<String> tabs)
    {
        tabTitleList.clear();
        tabTitleList.addAll(tabs);
    }

    public void setView(View view)
    {
        viewList.clear();
        viewList.add(view);
    }

    public void setView(List<View> views)
    {
        viewList.clear();
        viewList.addAll(views);
    }

    @Override
    public CharSequence getPageTitle(int position)
    {
        return tabTitleList.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object)
    {
        View view = viewList.get(position);
        container.removeView(view);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position)
    {
        View view = viewList.get(position);
        container.addView(view);
        return view;
    }

    @Override
    public int getCount()
    {
        return viewList.size();
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1)
    {
        return arg0 == arg1;
    }

}